package com.tang.transmission.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tang.common.entity.resumeTemplate.ResumeTemplate;
import com.tang.transmission.mapper.ResumeTemplateMapper;
import com.tang.transmission.service.ResumeTemplateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 唐朝阳
 * @since 2022-05-18
 */
@Service
public class ResumeTemplateServiceImpl extends ServiceImpl<ResumeTemplateMapper, ResumeTemplate> implements ResumeTemplateService {
    @Autowired
    private ResumeTemplateMapper resumeTemplateMapper;
    @Override
    public PageInfo<ResumeTemplate> listResume(String keywords, Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        if (keywords == null || "".equals(keywords)) {
            QueryWrapper<ResumeTemplate> qw = new QueryWrapper<ResumeTemplate>();
            qw.eq("delete_flag",1);
            qw.orderByDesc("create_time");
            return PageInfo.of(resumeTemplateMapper.selectList(qw));
        }
        QueryWrapper<ResumeTemplate> queryWrapper = new QueryWrapper<ResumeTemplate>();
        queryWrapper.eq("delete_flag",1).orderByDesc("create_time").
                and(qw->qw.like("name",keywords).or().like("admin_name",keywords));
        List<ResumeTemplate> rts = resumeTemplateMapper.selectList(queryWrapper);
        return  PageInfo.of(rts);
    }

    @Override
    public PageInfo<ResumeTemplate> listFilterResume(Integer currentPage, Integer pageSize, Integer filter) {
        PageHelper.startPage(currentPage,pageSize);
        QueryWrapper<ResumeTemplate> qw = new QueryWrapper<ResumeTemplate>();
        qw.eq("delete_flag",1);
        qw.eq("state",1);
        qw.orderByDesc("create_time");
        if(filter!=3){
            qw.eq("pay",filter);
        }
        return PageInfo.of(resumeTemplateMapper.selectList(qw));
    }
}
